{
  "name": "HR Employee Onboarding & Query Resolution Agent",
  "nodes": [
    {
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "id": "747b72ab-72ac-4b4b-9453-c4738b65c4f4",
      "name": "Telegram Trigger",
      "type": "n8n-nodes-base.telegramTrigger",
      "typeVersion": 1.2,
      "position": [
        0,
        0
      ],
      "webhookId": "e69fd63a-4cf6-443e-ac3e-4d7bcb04f5d2",
      "credentials": {
        "telegramApi": {
          "id": "NFpPTqiHG1arwJ14",
          "name": "Telegram account"
        }
      }
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "id-1",
              "name": "customer_message",
              "value": "={{ $json.message.text }}",
              "type": "string"
            },
            {
              "id": "id-2",
              "name": "customer_name",
              "value": "={{ $json.message.from.first_name + ' ' + ($json.message.from.last_name || '') }}",
              "type": "string"
            },
            {
              "id": "id-3",
              "name": "chat_id",
              "value": "={{ $json.message.chat.id }}",
              "type": "string"
            }
          ]
        },
        "includeOtherFields": true,
        "options": {}
      },
      "id": "b2faa358-d82f-487c-996d-d5f0205d8afd",
      "name": "Workflow Configuration",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        224,
        0
      ]
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=Customer Name: {{ $json.customer_name }}\nCustomer Message: {{ $json.customer_message }}\nChat ID: {{ $json.chat_id }}",
        "options": {
          "systemMessage": "=You are an HR Employee Onboarding and Query Resolution Assistant.\n\nYour responsibilities:\n1. Identify whether the employee wants to INITIATE onboarding or CHECK onboarding status or ASK policy queries.\n2. For new employee onboarding, collect:\n   - Employee ID\n   - Joining Date\n   - Department (e.g., Engineering, Sales, Marketing, Finance, HR, Operations, etc.)\n   - Brief query or document requirement\n3. Validate the employee using the Employee Master Database Tool and Extract the Employee_Name.\n4. If the employee record is valid:\n   - Generate a unique onboarding reference ID in format: ONB-YYYYMMDD-[last 4 digits of emp ID]-HHmmss\n   - Register the onboarding task using Onboarding Register Tool\n   - Send email confirmation using Gmail Tool\n   - Clearly explain next steps and document requirements\n   - Respond to the employee using Telegram Response Tool\n5. If the employee record is invalid or not found:\n   - Politely explain the reason\n   - Do not register onboarding\n   - Respond using Telegram Response Tool\n6. For status checks:\n   - Ask for onboarding reference number if missing\n   - Retrieve status using Onboarding Status Tool\n   - Explain the current stage in simple language\n   - Provide expected completion timeline\n   - Respond using Telegram Response Tool\n\nStrict rules:\n- Do NOT provide confidential salary or compensation information.\n- Do NOT make commitments outside standard HR policies.\n- Be clear, calm, and professional.\n- Maintain a welcoming, helpful tone - new employees may feel overwhelmed.\n- Avoid HR jargon.\n- Ask follow-up questions if information is missing.\n- ALWAYS use the Telegram Response Tool to send your final response to the employee."
        }
      },
      "id": "20d0be18-bcfc-450e-ba5e-ee00f5b44b5f",
      "name": "HR Onboarding Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 3,
      "position": [
        496,
        0
      ]
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "id",
          "value": "gpt-4o"
        },
        "builtInTools": {},
        "options": {
          "temperature": 0.2
        }
      },
      "id": "7f788952-6b47-4dbc-91be-0b7e9cfe1a3a",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.3,
      "position": [
        320,
        224
      ],
      "credentials": {
        "openAiApi": {
          "id": "ICwxUBbatsF2sDvy",
          "name": "OpenAi account"
        }
      }
    },
    {
      "parameters": {
        "sessionIdType": "customKey",
        "sessionKey": "={{ $('Workflow Configuration').item.json.chat_id }}",
        "contextWindowLength": 10
      },
      "id": "82962153-520f-4a30-9df1-909b4f6505fe",
      "name": "Simple Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "typeVersion": 1.3,
      "position": [
        480,
        224
      ]
    },
    {
      "parameters": {
        "descriptionType": "manual",
        "toolDescription": "Use this tool to validate employee information. Provide the employee ID to check if the employee exists, employment status, and department details. Returns employee_status, department, and joining_date.",
        "documentId": {
          "__rl": true,
          "value": "1CRsugg1k6BShT6m1EwJlJCE7FmR5FezYdAc3eps8wH0",
          "mode": "list",
          "cachedResultName": "Employee_Master_Database",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1CRsugg1k6BShT6m1EwJlJCE7FmR5FezYdAc3eps8wH0/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Sheet1",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1CRsugg1k6BShT6m1EwJlJCE7FmR5FezYdAc3eps8wH0/edit#gid=0"
        },
        "options": {}
      },
      "id": "9ccfaa85-e36f-420c-958f-c3a533d5eb75",
      "name": "Employee Master Database Tool",
      "type": "n8n-nodes-base.googleSheetsTool",
      "typeVersion": 4.7,
      "position": [
        640,
        224
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "LOs2dbk9lby0NfDM",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "descriptionType": "manual",
        "toolDescription": "=Use this tool to register a new onboarding task. Provide onboarding_reference_id, employee_id, joining_date, department, task_description, and onboarding_status (set to Initiated). This creates an official onboarding record.",
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "1gzuioH4Gg77ECQfsQBGk0CFeoedpc5p1PgrQCpI7SDI",
          "mode": "list",
          "cachedResultName": "Onboarding_Register",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1gzuioH4Gg77ECQfsQBGk0CFeoedpc5p1PgrQCpI7SDI/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Sheet1",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1gzuioH4Gg77ECQfsQBGk0CFeoedpc5p1PgrQCpI7SDI/edit#gid=0"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Onboarding_Ref_ID": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Onboarding_Ref_ID', ``, 'string') }}",
            "Employee_ID": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Employee_ID', ``, 'string') }}",
            "Employee_Name": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Employee_Name', ``, 'string') }}",
            "Joining_Date": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Joining_Date', ``, 'string') }}",
            "Department": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Department', ``, 'string') }}",
            "Task_Description": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Task_Description', ``, 'string') }}",
            "Onboarding_Status": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Onboarding_Status', ``, 'string') }}",
            "Created_At": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Created_At', ``, 'string') }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "Onboarding_Ref_ID",
              "displayName": "Onboarding_Ref_ID",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Employee_ID",
              "displayName": "Employee_ID",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Employee_Name",
              "displayName": "Employee_Name",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Joining_Date",
              "displayName": "Joining_Date",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Department",
              "displayName": "Department",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Task_Description",
              "displayName": "Task_Description",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Onboarding_Status",
              "displayName": "Onboarding_Status",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Created_At",
              "displayName": "Created_At",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "id": "f1b8eced-5df9-4f24-8278-a3ab354a8205",
      "name": "Onboarding Register Tool",
      "type": "n8n-nodes-base.googleSheetsTool",
      "typeVersion": 4.7,
      "position": [
        784,
        224
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "LOs2dbk9lby0NfDM",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "descriptionType": "manual",
        "toolDescription": "Use this tool to check the status of an existing onboarding task. Provide the onboarding_reference_id to retrieve current stage, last updated date, and completion status information.",
        "documentId": {
          "__rl": true,
          "value": "1ZC9iW1IqoC5OlCvUX08tI6uU8T3R-n1yz7C4Emcu_kI",
          "mode": "list",
          "cachedResultName": "Onboarding_Status",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1ZC9iW1IqoC5OlCvUX08tI6uU8T3R-n1yz7C4Emcu_kI/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Sheet1",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1ZC9iW1IqoC5OlCvUX08tI6uU8T3R-n1yz7C4Emcu_kI/edit#gid=0"
        },
        "options": {}
      },
      "id": "62745757-a7e6-4002-b850-fa6d36cf06be",
      "name": "Onboarding Status Tool",
      "type": "n8n-nodes-base.googleSheetsTool",
      "typeVersion": 4.7,
      "position": [
        928,
        224
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "LOs2dbk9lby0NfDM",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "descriptionType": "manual",
        "toolDescription": "Use this tool to send an official onboarding welcome email to the employee. Provide recipient email, onboarding reference ID, employee ID, and joining details including required documents and next steps.",
        "sendTo": "={{ $fromAI('customer_email', 'Customer email address', 'string') }}",
        "subject": "={{ $fromAI('email_subject', 'Email subject line', 'string', 'Welcome to the Team - Onboarding Confirmation') }}",
        "message": "={{ $fromAI('email_body', 'Email body content with onboarding details', 'string') }}",
        "options": {}
      },
      "id": "ba1015d8-26e0-481e-ac5f-e62fb4130470",
      "name": "Gmail Tool",
      "type": "n8n-nodes-base.gmailTool",
      "typeVersion": 2.1,
      "position": [
        1072,
        224
      ],
      "webhookId": "15cba1c5-81ac-4d4d-9a13-35fc51ad3bbe",
      "credentials": {
        "gmailOAuth2": {
          "id": "cyqCGWcggZNMcSOv",
          "name": "Gmail account"
        }
      }
    },
    {
      "parameters": {
        "chatId": "={{ $('Telegram Trigger').item.json.message.chat.id }}",
        "text": "={{ $json.output }}",
        "additionalFields": {}
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        928,
        0
      ],
      "id": "d74dc4e0-f783-4643-92e8-242ca666f514",
      "name": "Send a text message",
      "webhookId": "3c111795-fe7d-497d-b853-a6432330a256",
      "credentials": {
        "telegramApi": {
          "id": "NFpPTqiHG1arwJ14",
          "name": "Telegram account"
        }
      }
    }
  ],
  "pinData": {},
  "connections": {
    "Telegram Trigger": {
      "main": [
        [
          {
            "node": "Workflow Configuration",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Workflow Configuration": {
      "main": [
        [
          {
            "node": "HR Onboarding Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "HR Onboarding Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "HR Onboarding Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Employee Master Database Tool": {
      "ai_tool": [
        [
          {
            "node": "HR Onboarding Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Onboarding Register Tool": {
      "ai_tool": [
        [
          {
            "node": "HR Onboarding Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Onboarding Status Tool": {
      "ai_tool": [
        [
          {
            "node": "HR Onboarding Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Gmail Tool": {
      "ai_tool": [
        [
          {
            "node": "HR Onboarding Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "HR Onboarding Agent": {
      "main": [
        [
          {
            "node": "Send a text message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "489157c1-ee94-4606-9645-459113c4f56d",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "3a43da28588548e21903e71cf1dc3ddd65c24bf0c62e7e4b77542ffe87ad79c6"
  },
  "id": "R9QkaK1UMXwvuYjF",
  "tags": []
}